/*
 * claplan_frame.h
 *
 *  Created on: 31 Oct 2013
 *      Author: Tom Vercauteren
 */

#ifndef CLAPLAN_FRAME_H_
#define CLAPLAN_FRAME_H_

#include <wx/wx.h>
#include <wx/string.h>
#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/menuitem.h>
#include <wx/statusbr.h>
#include <wx/treectrl.h>
#include <wx/splitter.h>

#include "claplan_controller.h"
#include "claplan_tree.h"
#include "claplan_data_change_listener.h"
#include "debug.h"

class ClaplanController;
class ClaplanView;

class ClaplanView: public wxFrame, public ClaplanDataChangeListener
{
public:
	ClaplanView(const wxString& title);
	virtual ~ClaplanView();

	void claplanDataChanged();

	/**
	 * Creates all menu's and links all functionality to the corresponding functions.
	 */
	void createMenus();

	void createTree(wxWindow *parent);

	void createPanel();

	/**
	 * Adds a controller to the view which will regulate all functionality of the view to the data model.
	 * @param controller Controls the functionality of the view and communication to the data model.
	 */
	void setController(ClaplanController *controller);
	/**
	 * Removes the controller from the view.
	 */
	void removeController();
	/**
	 * Connect all functions related with tree events.
	 */
	void connectTreeEvents();
	/**
	 * Disconnect all functions related with tree events.
	 */
	void disconnectTreeEvents();

	int addClaplan(const std::string &name);
	int addClaplanSection(const std::string &name, const std::string &section);
	int removeClaplan(const std::string &name);
	int removeClaplanSection(const std::string &name,
			const std::string &section);
	void setTitle(const std::string &name);
private:
	/**
	 * Handles the event that a new file needs to be created.
	 * @param event
	 */
	void OnNewFile(wxCommandEvent& event);
	/**
	 * Handles the event that a file needs to be opened.
	 * @param event
	 */
	void OnOpen(wxCommandEvent& event);
	/**
	 * Handles the event that a file needs to be closed.
	 * @param event
	 */
	void OnClose(wxCommandEvent& event);
	/**
	 * Handles the event that a view needs to be closed.
	 * @param event
	 */
	void OnExit(wxCommandEvent& event);
	/**
	 * Triggered when the selection in the tree view changed
	 * @param event
	 */
	void OnSelectionChange(wxTreeEvent &event);

private:
	/** Controller that handles the real functionality of the view and the communication to the data model */
	ClaplanController* controller;
	wxMenuBar *menuBar;

	wxMenu *menuFile;
	wxMenuItem *menuItemNewFile;
	wxMenuItem *menuItemOpenFile;
	wxMenuItem *menuItemSaveFile;
	wxMenuItem *menuItemCloseFile;
	wxMenuItem *menuItemExit;

	wxMenu *menuHelp;
	wxMenuItem *menuItemAbout;

	/** Splitted window */
	wxSplitterWindow *splitw;

	/** Panels */
	wxPanel *leftPanel;
	wxPanel *rightPanel;

	/** Claplan tree */
	ClaplanTree *cltree;
};

#endif /* CLAPLAN_FRAME_H_ */
